<?php

namespace App\Kuafu\Mqtt\Controller\Merchant;

use App\Kuafu\Base\Controller\BaseController;
use App\Kuafu\User\Service\AuthService;
use App\Support\MQTT;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;

class MqttController extends BaseController
{
    public function getAccount(Request $request): JsonResponse
    {
        $userId      = AuthService::getUserId();
        $shopId      = $request->header("shopId");
        $connectType = $request->get('connectType');

        $this->validate($request, [
            'connectType' => ['required', 'integer', Rule::in(array_keys(MQTT::MQTT_CONNECT_TYPE_TEXT))],
        ]);

        $data = [
            'connectType' => $connectType,
            'account'     => MQTT::getAccountByConnectType($userId, $shopId, $connectType),
        ];

        return $this->success($data);
    }
}
